package br.com.utilitario;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Conexao {
	private final String HOST = "192.168.1.120" ;  
	private final String PORTA = "5432" ;  
	private final String BASE = "exemplo" ;  
	private final String USUARIO = "postgres" ;  
	private final String SENHA = "123456" ;  

	private Connection conn;

	public Connection conecta(String host, String porta, String base,
			String usuario, String senha) {
		try {
			Class.forName("org.postgresql.Driver");
			String url = String.format("jdbc:postgresql://%s:%s/%s", host,
					porta, base);
			try {
				conn = DriverManager.getConnection(url, usuario, senha);
			} catch (SQLException e) {
				e.printStackTrace();
			}

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

		return conn;
	}
	
	public Connection conecta() {
		try {
			Class.forName("org.postgresql.Driver");
			String url = String.format("jdbc:postgresql://%s:%s/%s", HOST,
					PORTA, BASE);
			try {
				conn = DriverManager.getConnection(url, USUARIO, SENHA);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		
		return conn;
	}

}
